import store from '@/store'
import constants from '@/module/constants.js'
import getSubOne from './ticket-data/sub-one'
import getSubTwo from './ticket-data/sub-two'
import getLineOne from './ticket-data/line-one'
import getLineTwo from './ticket-data/line-two'
import getCableOne from './ticket-data/cable-one'
import getCableTwo from './ticket-data/cable-two'
import getLineLiveWork from './ticket-data/line-livework'
import getsubRepair from './ticket-data/sub-repair'
import getCommunication from './ticket-data/communication'
import getInformation from './ticket-data/information'
import getLowpresure from './ticket-data/lowpresure'
import getlineRepair from './ticket-data/line-repair'
import getSubLiveWork from './ticket-data/sub-livework'

import getSubChildOne from './ticket-data/sub-child-one'
import getLineChildOne from './ticket-data/line-child-one'
import getLineChildTwo from './ticket-data/line-child-two'
import getCableChildOne from './ticket-data/cable-child-one'
import getCableChildTwo from './ticket-data/cable-child-two'
import getLineChildLiveWork from './ticket-data/line-child-live-work'

export const getDetail = async (type, id = '') => {
  return new Promise((resolve) => {
    let detailData = {}
    const isChildTicket = type.indexOf('Child') > -1
    let interfaceQuest = null
    if (isChildTicket) {
      interfaceQuest = store.dispatch('getTicketByParam', { partWorkTicketId: id })
    } else {
      const receive = {
        ticketType: constants.typeMajor[type],
        workTicketId: id
      }
      interfaceQuest = store.dispatch('getDetail', receive)
    }
    interfaceQuest.then(res => {
      const { saveSign = '', ticket } = res
      let { availableColumns = [] } = res
      store.commit('SET_SAVESIGN', saveSign)
      const ticketData = isChildTicket ? res : ticket
      if (ticketData) {
        switch (type) {
          case 'subOne':
            detailData = getSubOne(ticketData)
            break
          case 'subTwo':
            detailData = getSubTwo(ticketData)
            break
          case 'lineOne':
            detailData = getLineOne(ticketData)
            break
          case 'lineTwo':
            detailData = getLineTwo(ticketData)
            break
          case 'cableOne':
            detailData = getCableOne(ticketData)
            break
          case 'cableTwo':
            detailData = getCableTwo(ticketData)
            break
          case 'lineLiveWork':
            detailData = getLineLiveWork(ticketData)
            break
          case 'subRepair':
            detailData = getsubRepair(ticketData)
            break
          case 'communication':
            detailData = getCommunication(ticketData)
            break
          case 'information':
            detailData = getInformation(ticketData)
            break
          case 'lowpresure':
            detailData = getLowpresure(ticketData)
            break
          case 'lineRepair':
            detailData = getlineRepair(ticketData)
            break
          case 'subLiveWork':
            detailData = getSubLiveWork(ticketData)
            break
          case 'subChildOne':
            detailData = getSubChildOne(ticketData)
            break
          case 'lineChildOne':
            detailData = getLineChildOne(ticketData)
            break
          case 'lineChildTwo':
            detailData = getLineChildTwo(ticketData)
            break
          case 'cableChildOne':
            detailData = getCableChildOne(ticketData)
            break
          case 'cableChildTwo':
            detailData = getCableChildTwo(ticketData)
            break
          case 'lineChildLiveWork':
            detailData = getLineChildLiveWork(ticketData)
            break
        }
      }
      resolve({ availableColumns, detailData })
    })
  })
}
